using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using Module.DataAccess;
using Module.EntitiesInfo;

namespace Module.BusinessLogic
{
    public class CMSGameBL
	{		
		public static int Insert(CMSGameInfo cMSGameInfo)
		{
			try
			{
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
				return new CMSGameDB().Insert(cMSGameInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        public static void Update(CMSGameInfo cMSGameInfo)
		{
			try
			{
				new CMSGameDB().Update(cMSGameInfo);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
			}
			catch (Exception ex)
			{
				throw;
			}

		}


        public static void Delete(int idGame)
		{
			try
			{
				new CMSGameDB().Delete(idGame);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        public static List<CMSGameInfo> Select(int type, string param_1, string param_2)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSGameInfo>(new CMSGameDB().Select(type, param_1, param_2));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<CMSGameInfo> SelectInsite(int type, string param_1, string param_2)
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = type + "_" + param_1 + "_" + param_2 + "{A38F7C85-B104-4007-9677-1412703E63A5}";
                List<CMSGameInfo> info = new List<CMSGameInfo>();
                if (cache.GetCache(strCache) != null)
                {
                    info = (List<CMSGameInfo>)(cache.GetCache(strCache));
                    return info;
                }
                info = ObjectHelper.FillCollection<CMSGameInfo>(new CMSGameDB().Select(type, param_1, param_2));
                if (info != null && info.Count > 0)
                {
                    cache.InsertCache(strCache, info, Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return info;                   
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<CMSGameInfo> Select(int type, string param_1)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSGameInfo>(new CMSGameDB().Select(type, param_1));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<CMSGameInfo> Select(int type)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSGameInfo>(new CMSGameDB().Select(type));
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static DataTable SelectTbl(int? type, string para_1, string para_2)
        {
            try
            {
                return new CMSGameDB().SelectTbl(type, para_1, para_2);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static DataTable SelectTbl(int? type, string para_1)
        {
            try
            {
                return new CMSGameDB().SelectTbl(type, para_1);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static DataTable SelectTbl(int? type)
        {
            try
            {
                return new CMSGameDB().SelectTbl(type);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static CMSGameInfo GetInfo(int type, string para_1, string para_2)
        {
            try
            {
                CMSGameInfo info;
                info = ObjectHelper.FillObject<CMSGameInfo>(new CMSGameDB().Select(type, para_1, para_2));
                if (info != null)
                    return info;
                return null;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static int GetCount(string keysearch, int clubId, int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow)
        {
            try
            {
                return new CMSGameDB().GetCount(keysearch, clubId, status, starDatetime, endDatetime, beginRow, endRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable Search(string keysearch, int clubId, int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new CMSGameDB().Search(keysearch, clubId, status, starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static void UpdateStatus(int footBallId, int status, int param)
        {
            try
            {
                new CMSGameDB().UpdateStatus(footBallId, status, param);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static DataTable GetTop()
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = "{7C4328FF-0C56-4393-BBE1-E1EF95A2F52B}";
                DataTable dt = new DataTable();
                if (cache.GetCache(strCache) != null)
                {
                    dt = (DataTable)(cache.GetCache(strCache));
                    return dt;
                }
                dt = new CMSGameDB().GetTop();
                if (dt != null && dt.Rows.Count > 0)
                {
                    cache.InsertCache(strCache, dt, Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return dt;  
                
            }
            catch (Exception ex)
            {
                throw;
            }

        }
	}
}
